package concurrent.collection;

import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

public class CopyOnWriteArrayListTest {

    public static void main(String[] args) throws InterruptedException {

        final List<Integer> listTest = new CopyOnWriteArrayList<>();
        listTest.add(1);
        listTest.add(2);
        listTest.add(3);

        Integer a = listTest.get(2);
        System.out.println(a);
        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
                listTest.remove(2);
            }
        });
        thread.start();
//        for(int i = 0; i<listTest.size(); i++){
//            System.out.println(listTest.get(i));
//            Thread.sleep(1000);
//        }

        Thread.sleep(1000);
        //期望得到3,但数组越界啦
        Integer b = listTest.get(2);
        System.out.println(b);

    }
}
